package com.bosssoft.itfinance.citizen.doc.controller;
import com.alibaba.fastjson.JSONObject;
import com.bosssoft.itfinance.citizen.doc.common.util.DocScanPathUtils;
import com.bosssoft.itfinance.citizen.doc.controller.resp.ClassBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * Created by wangml on 2017/8/25.
 */
@Controller
@RequestMapping("/doc")
public class DocController {
    private static List<ClassBean> cbList;

    /**
     * 获取doc数据
     * @return
     */
    @RequestMapping("/query")
    @ResponseBody
    public Object queryDoc()throws Exception {
        if(cbList == null) {
            cbList = new ArrayList<>();
            Set<Class<?>> classes = DocScanPathUtils.getClasses("com.bosssoft.itfinance.citizen");
            for (Class clz : classes) {
                ClassBean cb = DocScanPathUtils.getClassBean(clz);
                if (cb != null) {
                    cbList.add(cb);
                }
            }
        }
        JSONObject rst = new JSONObject();
        JSONObject businessMsg = new JSONObject();
        businessMsg.put("businessCode","0");
        businessMsg.put("businessNote","Success");
        rst.put("code","ok");
        rst.put("data",cbList);
        rst.put("businessMsg",businessMsg);
        return  rst;
    }


}
